﻿using System;
using System.Collections.Generic;
using UnityEngine;
using Framework.Define;
using Framework.Manager;
using Framework.Util;
using Framework.Scene;

namespace Framework.Manager
{
    public class SceneManager : ManagerBase<SceneManager>
    {
        private SceneManager() { }

        public void LoadScene<T>() where T : SceneBase<T>
        {
            string sceneName = GetSceneName<T>();
            ManagerCollection.LoadManager.LoadSceneAsyc(sceneName, (bool pState) =>
             {
                 string path = FrameworkDefine.SceneRootPath;
                 GameObject sceneRoot = UtilCollection.GameObjectUtil.FindOrCreateGameObject(path);
                 SceneBase<T> sceneBase = sceneRoot.AddComponent<T>();
                 sceneBase.Init();
             });
        }

        private string GetSceneName<T>()
        {
            Type type = typeof(T);
            return type.Name;
        }
    }
}